package com.yuanshi.food.common.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * RabbitMQ消费者配置
 *
 * @author wcy
 * @date 2025/10/16
 */
@Slf4j
@Configuration
public class RabbitMQConsumerConfig {
    
    /**
     * 用户注册事件交换机
     */
    private static final String USER_REGISTER_EXCHANGE = "user.register.exchange";
    
    /**
     * 用户注册事件队列
     */
    private static final String USER_REGISTER_QUEUE = "user.register.queue";
    
    /**
     * 用户注册事件路由键
     */
    private static final String USER_REGISTER_ROUTING_KEY = "user.register.routing.key";
    
    /**
     * 用户注册事件交换机
     *
     * @return DirectExchange
     */
    @Bean
    public TopicExchange userRegisterExchange() {
        return new TopicExchange(USER_REGISTER_EXCHANGE, true, false);
    }
    
    /**
     * 用户注册事件队列
     *
     * @return Queue
     */
    @Bean
    public Queue userRegisterQueue() {
        return QueueBuilder.durable(USER_REGISTER_QUEUE).build();
    }

    /**
     * 用户注册事件绑定
     *
     * @param userRegisterQueue    用户注册事件队列
     * @param userRegisterExchange 用户注册事件交换机
     * @return Binding
     */
    @Bean
    public Binding userRegisterBinding(Queue userRegisterQueue, TopicExchange userRegisterExchange) {
        return BindingBuilder.bind(userRegisterQueue).to(userRegisterExchange).with(USER_REGISTER_ROUTING_KEY);
    }
    
}